﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows.Forms;

namespace DamageCalculator.Classes
{
    class ListViewItemComparer: IComparer
    {
        int mCol;

        public ListViewItemComparer(int Col)
        {
            this.mCol = Col;
        }

        public int Compare(object x, object y)
        {
            try
            {
                if (double.Parse(((ListViewItem)x).SubItems[this.mCol].Text) > double.Parse(((ListViewItem)y).SubItems[this.mCol].Text))
                    return -1;

                if (double.Parse(((ListViewItem)x).SubItems[this.mCol].Text) < double.Parse(((ListViewItem)y).SubItems[this.mCol].Text))
                    return 1;

                return 0;
            }

            catch
            {
                return String.Compare(((ListViewItem)x).SubItems[this.mCol].Text, ((ListViewItem)y).SubItems[this.mCol].Text);
            }
        }
    }
}
